import axios from 'axios'
import { Dispatch } from 'redux'
import Cookies from "js-cookie"
import { anyAction } from '../untils'
export let login=(values:any)=>{
    return async(dispatch:Dispatch)=>{
    let {data}=await axios.get("/api/login",{params:values})
    Cookies.set("token",data.token,{expires:1})
    dispatch({
        type:"LOGIN",
        payload:Object.assign({},values,{...data})
    })
    
    }
}

export let reg=(values:any)=>{
    return async(dispatch:Dispatch)=>{
    let {data}=await axios.get("/api/reg",{params:values})
    console.log(data);
    dispatch({
        type:"REG",
        payload:Object.assign({},values,{...data})
    })
    }
}

export let getlist=()=>{
    return async(dispatch:Dispatch)=>{
    let {data}=await axios.get("/api/list")
    // console.log(data);
    dispatch({
        type:"GET_LIST",
        payload:data.list
    })
    }
}

export let show_item=(item:anyAction)=>{
   return {
    type:"SHOW_ITEM",
    payload:item
   }
}

export let getlist1=()=>{
    return async(dispatch:Dispatch)=>{
    let {data}=await axios.get("/api/list1")
    // console.log(data);
    dispatch({
        type:"GET_LIST1",
        payload:data.list
    })
    }
}

export let filterlist1=(values:any)=>{
   return {
   type:"FILTERLIST",
   payload:values
   }
}
